package com.whir.rd.service.parse;

import com.whir.rd.service.api.sendFlow.QMSSendEzFlowService;
import com.whir.service.common.AbstractParse;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.jdom.Document;
import org.jdom.Element;

public class QMSSendFlowParse extends AbstractParse{
	private static Logger logger = Logger.getLogger(QMSSendFlowParse.class.getName());
	public QMSSendFlowParse(Document doc) {
		super(doc);
	}
	
	
	

	public String qmsSendFlow() {
        System.out.println("===================webservice===================");
        logger.debug("--sendEzFlow webservice is start!--");
        String result = "";
        Element rootElement = this.doc.getRootElement();
        QMSSendEzFlowService service = new QMSSendEzFlowService();
        String infoId = service.saveQmsForm(rootElement);
        if (infoId == null) {
            this.setMessage("0", "保存流程数据时异常");
            return result;
        } else if ("-3".equals(infoId)) {
            this.setMessage("0", "保存数据时异常");
            return result;
        } else if ("-6".equals(infoId)) {
            this.setMessage("0", "OA系统已存在此数据，不能重复推送");
            return result;
        } else if ("-1".equals(infoId)) {
            this.setMessage("0", "OA系统中没有此账号的用户信息，无法发起流程");
            return result;
        } else {
        	System.out.println("=============service.sendQMSFlowInstance========================");
            String results = service.sendQMSFlowInstance(rootElement, infoId);
            if ("-5".equals(results)) {
                this.setMessage("0", "无法找到下一活动办理人，请确认下一节点办理人账号是否正确");
                return result;
            }  else if ("-6".equals(results)) {
                this.setMessage("0", "参数错误");
                return result;
            } else if ("-4".equals(results)) {
                this.setMessage("0", "发送流程异常");
                return result;
            } else {
                result = "<output><infoId>" + infoId + "</infoId></output>";
                this.setMessage("1", "发送流程成功");
                logger.debug("--sendEzFlow webservice is end!--");
                return result;
            }
        }
    }
	

}
